//  三星 https://iai.sh.cn/problem/553
#include <bits/stdc++.h>
using namespace std;

int a[500001];
long long sum[500001];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[n + i] = a[i];
    a[2 * n + i] = a[i]; // 环状拆成直线
  }
  int left, right;
  if (n % 2 == 0) {
    left = n / 2;
    right = n / 2 - 1;
  } else {
    left = n / 2;
    right = n / 2;
  }

  for (int i = 1; i <= 3 * n; i++)
    sum[i] = sum[i - 1] + a[i];

  long long king = 0x3f3f3f3f3f3f3f3f;
  int p = n + 1;
  // 求位置 p-left 到 p-1 的搬运初始值
  long long L = 0;
  for (int i = p - left; i <= p - 1; i++)
    L = L + (p - i) * a[i];
  // 求位置 p+1 到 p+right 的和
  //  求 R的 初始值
  long long R = 0;
  for (int i = p + 1; i <= p + right; i++)
    R = R + (i - p) * a[i];

  king = min(king, R + L);
  // 不断的迭代
  for (int i = n + 2; i <= 2 * n; i++) {
    L = L + sum[i - 1] - sum[i - left - 1] - a[i - 1] * left;
    R = R - (sum[i + right - 1] - sum[i - 1]) + a[i + right] * right;
    king = min(king, R + L);
  }
  cout << king;
  return 0;
}